Read a file to multiple array byte[]

Posted by hankol on Stack Overflow See other posts from Stack Overflow or by hankol
Published on 2012-11-07T16:52:21Z Indexed on 2012/11/07 17:00 UTC
Read the original article Hit count: 158

Filed under:
|
|

I have an encryption algorithm (AES) that accepts file converted to array byte and encrypt it. Since I am going to process a very big size files, the JVM may go out of memory. I am planing to read the files in multiple array byte. each containing some part of the file. Then I teratively feed the algorithm. Finally merge them to produce encrypted file.

So my question is: there any way to read a file part by part to multiple array byte?

I thought I can use the following to read the file to array byte:

    IOUtils.toByteArray(InputStream input).

And then split the array into multiple bytes using:

    Arrays.copyOfRange().

But I am afraid that the first code that reads file to byte will make the JVM to go out of memory.

any suggestion please ?

thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about file